package com.example.demo.controller.system;

import com.example.demo.annoation.Log;
import com.example.demo.bean.AjaxRes;
import com.example.demo.bean.sysrolemenu.SysRoleMenuDO;
import com.example.demo.controller.BaseAdminController;
import com.example.demo.enums.BusinessType;
import com.example.demo.service.ISysRoleMenuService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping(value = "/system/role_menu")
@RestController
public class SysRoleMenuController extends BaseAdminController {

    @Resource
    private ISysRoleMenuService sysRoleMenuService;

    @PostMapping("/insert")
    @Log(title = "新增角色菜单", businessType = BusinessType.INSERT)
    public AjaxRes insert(@RequestBody SysRoleMenuDO sysRoleMenuDO) {
        return toAjax(sysRoleMenuService.addSysRoleMenu(sysRoleMenuDO));
    }

    @PutMapping("/update")
    @Log(title = "更新角色菜单", businessType = BusinessType.UPDATE)
    public AjaxRes update(@RequestBody SysRoleMenuDO sysRoleMenuDO) {
        log.info("SysRoleMenuDO:{}",sysRoleMenuDO.toString());
        return toAjax(sysRoleMenuService.updateSysRoleMenu(sysRoleMenuDO));
    }

    @GetMapping("/{roleId}")
    public AjaxRes query(@PathVariable("roleId") Long roleId) {
        return AjaxRes.success(sysRoleMenuService.getSysRoleMenuByRoleId(new SysRoleMenuDO().setRoleId(roleId)));
    }
}
